package com.practice.mybpapi.domain.dto;

import cn.hutool.core.util.StrUtil;
import com.baomidou.mybatisplus.core.metadata.OrderItem;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.practice.mybpapi.domain.po.User;
import io.swagger.annotations.ApiModelProperty;
import io.swagger.annotations.ApiOperation;
import lombok.Data;

@Data
public class PageUserQuery {
    @ApiModelProperty("用户名关键字")
    private String name;
    @ApiModelProperty("用户状态：1-正常，2-冻结")
    private Integer status;
    @ApiModelProperty("是否升序")
    private Boolean isAsc;
    @ApiModelProperty("排序字段")
    private String sortBy;
    @ApiModelProperty("页码")
    private  Integer pageNo;
    @ApiModelProperty("每页数量")
    private  Integer pageSize;
    public Page<User> toMapPageSortByUpdateTime(){
        Page<User> page = Page.of(this.getPageNo(), this.getPageSize());
        if (StrUtil.isNotBlank(this.getSortBy())){
            page.addOrder(this.getIsAsc() ? OrderItem.asc(this.getSortBy()) : OrderItem.desc(this.getSortBy()));
        }else{
            page.addOrder(this.getIsAsc() ? OrderItem.asc("update_time") : OrderItem.desc("update_time"));
        }
        return page;
    }
}
